package com.example.testrxjava.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.testrxjava.R;
import com.example.testrxjava.fragment.home.HomeListBean;
import com.example.testrxjava.util.ImageUtil;

import java.util.List;

/**
 * 项目名称：TestRxjava
 *
 * @Author 郭迎辉
 * Create by 14:53 on 2019/4/18.
 * Describe:
 */
public class HomeListAdapter extends BaseQuickAdapter<HomeListBean.DataBean.DatasBean, BaseViewHolder> {
    public HomeListAdapter(int layoutResId, @Nullable List<HomeListBean.DataBean.DatasBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeListBean.DataBean.DatasBean item) {
        if(item == null) return;


        helper.setText(R.id.homeItemAuthorTv,item.getAuthor())
                .setText(R.id.homeItemDateTv,item.getNiceDate())
                .setText(R.id.homeItemTitleTv, Html.fromHtml(item.getTitle()))
                .setText(R.id.homeItemTypeTv,item.getSuperChapterName()+" / "+item.getChapterName())
                .addOnClickListener(R.id.homeItemLoveIv);

        if(item.isCollect()){
            helper.getView(R.id.homeItemLoveIv).setSelected(true);
        }else{
            helper.getView(R.id.homeItemLoveIv).setSelected(false);
        }
    }



//    static class ViewHolder extends RecyclerView.ViewHolder{
//        TextView homeItemAuthorTv;//作者
//        TextView homeItemDateTv;//日期
//        TextView homeItemTitleTv;//标题
//        TextView homeItemTypeTv;//类型
//        ImageView homeItemLoveIv;//心。收藏
//        public ViewHolder(@NonNull View itemView) {
//            super(itemView);
//            homeItemAuthorTv=itemView.findViewById(R.id.homeItemAuthorTv);
//            homeItemDateTv=itemView.findViewById(R.id.homeItemDateTv);
//            homeItemTitleTv=itemView.findViewById(R.id.homeItemTitleTv);
//            homeItemTypeTv=itemView.findViewById(R.id.homeItemTypeTv);
//            homeItemLoveIv=itemView.findViewById(R.id.homeItemLoveIv);
//
//
//        }
//    }
}
